package net.halflite.mzkr.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import net.halflite.mzkr.type.ImageExtensionType;

import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * UserImageエンティティクラス
 * 
 */
@Entity
public class UserImage implements Serializable {

    private static final long serialVersionUID = 1L;

    /** 画像の最大サイズ(KB) */
    public static final int SIZE_MAX = 800;

    /** 大きいアイコンサイズ(ピクセル) */
    public static final int LARGE = 125;
    
    /** 小さいアイコンサイズ(ピクセル) */
    public static final int SMALL = 50;
    
    /** 極小アイコンサイズ(ピクセル) */
    public static final int ICON = 25;

    /** idプロパティ */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public long id;

    /** registedUserIdプロパティ */
    public long registedUserId;

    /** bytesプロパティ */
    @Lob
    public byte[] bytes;

    /** extプロパティ */
    @Enumerated(EnumType.STRING)
    public ImageExtensionType ext;

    /** createdプロパティ */
    @Column(updatable = false)
    @Temporal(TemporalType.TIMESTAMP)
    public Date created;

    /** modifiedプロパティ */
    @Temporal(TemporalType.TIMESTAMP)
    public Date modified;

    /** registedUser関連プロパティ */
    @ManyToOne
    @JoinColumn(name = "registed_user_id", referencedColumnName = "id")
    public RegistedUser registedUser;

    public UserImage(long registedUserId) {
		this.registedUserId = registedUserId;
		created = new Date();
		modified = new Date();
	}
	
    public UserImage() {
	}

	@Override
	public String toString() {
		return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
			.setExcludeFieldNames(new String[]{"bytes", "registedUser"}).toString();
	}
}